package com.study.a06mySet;

import java.util.HashSet;

public class A02_HashSetDemo2 {
    public static void main(String[] args) {


        Student s1=new Student("张三",18);
        Student s2=new Student("李四",13);
        Student s3=new Student("王五",28);
        Student s4=new Student("张三",18);

        //创建集合来添加学生
        HashSet<Student> hs = new HashSet<>();
        hs.add(s1);
        hs.add(s2);
        hs.add(s3);
        hs.add(s4);

        //重写hashCode方法和equals方法后，属性值相同哈希值相同
        //如果数据为String和Integer类型，不用重写hashCode和equals方法
        System.out.println(hs);


        System.out.println(s1.hashCode());//713338599
        System.out.println(s2.hashCode());//168423058



    }
}
